package eu.szemraj.net.services {
    import flash.utils.Dictionary;

    public class ServiceLocator {

        [ArrayElementType("IService")]
        private var _services:Dictionary; /* of IService */

        public function ServiceLocator() {
      	
            super( );
            _services = new Dictionary( );
        }

        /**
         * Adds service
         * @param service service to add
         */
        public function addService( service:IService ):void {
      	
            _services[ service.name ] = service;
        }

        /**
         * Returns service by sevice name.
         * @param serviceName name of service
         * @return null, if service with given name is not registered
         */
        public function getService( serviceName:String ):IService {
      	
      	
            if( !hasService( serviceName )) return null;
      	else return _services[ serviceName ] as IService;
        }

        /**
         * Chekcs if service with given name is registered
         * @param serviceName name of service
         * @return true, if service is registered, otherwise false
         */
        public function hasService( serviceName:String ):Boolean {
      	
            return _services[ serviceName ] != null;	
        }
    }
}
